package cn.jja8.config.tool.work.obj.common;


import java.util.HashMap;
import java.util.Map;

public class CommonKeepManager {
    final Map<Class, CommonKeep> fieldAsMap = new HashMap<>();
    public CommonKeepManager() {
        add(new KeepFile());
        add(new KeepLBoolean());
        add(new KeepLByte());
        add(new KeepLChar());
        add(new KeepLDouble());
        add(new KeepLFloat());
        add(new KeepLInt());
        add(new KeepLLong());
        add(new KeepLShort());
        add(new KeepOBoolean());
        add(new KeepOByte());
        add(new KeepOChar());
        add(new KeepODouble());
        add(new KeepOFloat());
        add(new KeepOInt());
        add(new KeepOLong());
        add(new KeepOShort());
        add(new KeepString());
        add(new KeepURL());
        add(new KeepUUID());
    }
    public <T> void add(CommonKeep<T> basicFieldAs){
        fieldAsMap.put(basicFieldAs.Type(),basicFieldAs);
    }
    public <T> CommonKeep<T> get(Class<T> type){
        return fieldAsMap.get(type);
    }
    public <T> CommonKeep<T> getNoNull(Class<T> type){
        CommonKeep commonKeep = fieldAsMap.get(type);
        if (commonKeep==null){
            throw new Error("没有找到合适的用于"+type+"的CommonKeep");
        }
        return commonKeep;
    }
}
